import java.io.*;
import java.util.UUID;

import com.obs.services.ObsClient;
import com.obs.services.ObsConfiguration;
import com.obs.services.exception.ObsException;
import com.obs.services.model.*;


/**
 * This sample demonstrates how to upload multiparts to OBS
 * using the OBS SDK for Java.
 */
public class SimpleMultipartUploadSample {
    static String endPoint = "obs.cn-east-2.myhwclouds.com";
    static String ak = "JSG91U5FMOQUK7BHWCCC";
    static String sk = "ztnum0YlqbNZeNRnXD7UwXExlEtCwwzOj1FuNrHY";

    private static ObsClient obsClient;

    private static String bucketName = "my-obs-bucket-demo";

    private static String objectKey = "my-obs-object-key-demo";

    public static void main(String[] args) throws IOException {
        ObsClient obsClient = new ObsClient(ak, sk, endPoint);
        ObsObject obsObject = obsClient.getObject("obs-50b9", "xiaolaba.sql");
        InputStream content = obsObject.getObjectContent();
        if (content != null) {
            BufferedReader reader = new BufferedReader(new InputStreamReader(content));
            while (true) {
                String line = reader.readLine();
                if (line == null)
                    break;
                System.out.println("\n" + line);
            }
            reader.close();
        }


    }

    private static File createSampleFile()
            throws IOException {
        File file = File.createTempFile("obs-java-sdk-", ".txt");
        file.deleteOnExit();

        Writer writer = new OutputStreamWriter(new FileOutputStream(file));
        for (int i = 0; i < 1000000; i++) {
            writer.write(UUID.randomUUID() + "\n");
            writer.write(UUID.randomUUID() + "\n");
        }
        writer.flush();
        writer.close();

        return file;
    }
}
